{{- if (.Values.global.enabledModules | has "operator-prometheus-crd") }}
---
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
  name: terraform-state-exporter
  namespace: d8-monitoring
  {{- include "helm_lib_module_labels" (list . (dict "prometheus" "main")) | nindent 2 }}
spec:
  jobLabel: app
  podMetricsEndpoints:
  - port: https-metrics
    scheme: https
    bearerTokenSecret:
      name: "prometheus-token"
      key: "token"
    tlsConfig:
      insecureSkipVerify: true
    honorLabels: true
    scrapeTimeout: {{ include "helm_lib_prometheus_target_scrape_timeout_seconds" (list . 25) }}
    relabelings:
    - sourceLabels: [__meta_kubernetes_pod_ready]
      regex: "true"
      action: keep
    - regex: endpoint|namespace
      action: labeldrop
  selector:
    matchLabels:
      app: terraform-state-exporter
  namespaceSelector:
    matchNames:
    - d8-system
{{- end }}
